﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.SqlClient;
using System.Data;

namespace Acms.SqlDal
{
    public class RedirectDal : Base
    {
        public enum Fields
        {
            Id,
            SiteId,
            OriginalUrl,
            TargetUrl,
            HttpCode
        }

        protected override void ReadRecord(System.Collections.Hashtable table, System.Data.SqlClient.SqlDataReader reader)
        {
            GetReaderValue<int>(Fields.Id, reader, table);
            GetReaderValue<int>(Fields.SiteId, reader, table);
            GetReaderValue<string>(Fields.OriginalUrl, reader, table);
            GetReaderValue<string>(Fields.TargetUrl, reader, table);
            GetReaderValue<int>(Fields.HttpCode, reader, table);
        }

        public Hashtable[] GetAllBySiteId(int siteId)
        {
            SqlCommand cmd = CreateCommand("GetAllBySiteId");
            AddInputParameter(cmd, "SiteId", siteId, SqlDbType.Int);
            return ExecuteGetCollection(cmd);
        }

        public Hashtable[] GetAllBySiteUrl(string siteUrl)
        {
            SqlCommand cmd = CreateCommand("GetAllBySiteUrl");
            AddInputParameter(cmd, "SiteUrl", siteUrl, SqlDbType.VarChar, 50);
            return ExecuteGetCollection(cmd);
        }
    }
}
